package com.itheima.demo003;

import java.util.Scanner;

public class test9 {
    public static void main(String[] args) {
        //1.定义两个变量，记录正确的用户名和密码
        String rightUsername = "不服输的宋同学";
        String rightPassword = "654321";

        //2.键盘录入用户名和密码
        for (int i = 0; i < 3; i++) {//0,1,2
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名");
            String username = sc.next();
            System.out.println("请输入密码");
            String password = sc.next();

            //3.比较
            if(username.equals(rightUsername) && password.equals(rightPassword)){
                System.out.println("用户登录成功");
                break;
            }else{
                System.out.println("用户登录失败，用户名或密码有误，您还剩下" + (2 - i) + "次机会");//2，1，0
            }
        }

    }
}
